﻿using UnityEngine;
using System.Collections;
using FrenzyIsland.UI;
using System.Collections.Generic;

public class CharacterMouseAction : MonoBehaviour{
    public GameObject SelectionObject;
    public GameObject SelectionMenu;
    public float rotationSpeed = 2;

    private GameObject selectionObjectInstance;

    public void OnMouseEnter(){
        if (this.selectionObjectInstance == null) {
            if (this.SelectionObject != null) {
                this.selectionObjectInstance = Instantiate(SelectionObject) as GameObject;
                this.selectionObjectInstance.name = "SelectorObject";
                this.selectionObjectInstance.transform.parent = transform;
                this.selectionObjectInstance.transform.localScale = new Vector3(2f, 0.001f, 2f);
                this.selectionObjectInstance.transform.localPosition = new Vector3(0, 0.3f, 0);
                MeshRenderer rend = this.selectionObjectInstance.GetComponent<MeshRenderer>();
                rend.material.color = Color.yellow;
            }  
        }
    }


    public void OnMouseExit(){
        if (this.selectionObjectInstance != null) {
            Destroy(this.selectionObjectInstance);
            this.selectionObjectInstance = null;
        } 
    }

    /// <summary>
    /// Esegue l'azione specificata per ogni tipo di oggetto
    /// Cambia il colore
    /// </summary>
    public void OnMouseDown(){
        if (UICamera.lastHit.collider == null) {
            GuiManager guiManager = UIRoot.list[0].GetComponent<GuiManager>();
            GameObject widget = guiManager.openWidget(SelectionMenu);
            widget.GetComponent<SelectedCharacterModel>().steveBrain = this.GetComponent<SteveBrain>();
            widget.GetComponent<SelectedCharacterModel>().peopleCtrl = FrenzyPeopleController.instance;
        }
    }
}
